<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="js/jqplot/jquery.jqplot.min.css" />
<link type="text/css" rel="stylesheet" href="js/util/util.css">

<title>组员行为图</title>
</head>
<body>

<div id="chart1b"></div>
<div id="legend1b"></div>
  <div id="actionTB" >
        <div class="action-item add"></div>
        <label>添加文本</label>

        <div class="action-item replace"></div>
        <label>修改文本</label>

        <div class="action-item remove"></div>
        <label>删除文本</label>
         
         <div class="action-item see"></div>
        <label>查看群体感知图</label>
        
        
        <div class="action-item comment"></div>
        <label>评论</label>
        
        <div class="action-item grade"></div>
        <label>打分</label>
        
        <div class="action-item reply"></div>
        <label>回复评论</label>
       
    </div>
<script type="text/javascript" src="js/jqplot/jquery.min.js"></script>
<script type="text/javascript" src="js/jqplot/jquery.jqplot.min.js"></script>
<script type="text/javascript" src="js/jqplot/jqplot.bubbleRenderer.min.js"></script>
<script type="text/javascript" src="js/jqplot/jqplot.bubbleRenderer.js"></script>
<script type="text/javascript" src="js/jqplot/jqplot.dateAxisRenderer.js"></script>
<script type="text/javascript" src="js/jqplot/jqplot.cursor.min.js"></script>
<script type="text/javascript" src="js/jqplot/jqplot.highlighter.min.js"></script>
<script type="text/javascript">

/*
 * 创建行为图
 */
$(document).ready(function(){
	//获取小组名
	var url = window.location+'';
	var number =url.split("?")[1];
	var assId=url.split("?")[2];
	var g_type=url.split("?")[3];//1:个人  2：小组
	//var _version=[{"sumCount":8,"atext":{"text":"测试作业123\n","attribs":"|1+8"},"revs":0,"author":"","textCount":8,"cmd":"add","timestamp":1491319761003},{"sumCount":8,"revs":1,"author":"a.La7mDukNWjbLvEOg","textCount":4,"cmd":"replace","timestamp":1491319809801},{"sumCount":9,"revs":2,"author":"","textCount":2,"cmd":"add","timestamp":1491319809803},{"sumCount":17,"revs":3,"author":"a.La7mDukNWjbLvEOg","textCount":9,"cmd":"add","timestamp":1491319811032},{"sumCount":25,"revs":4,"author":"a.La7mDukNWjbLvEOg","textCount":9,"cmd":"add","timestamp":1491319907086},{"sumCount":26,"revs":5,"author":"","textCount":2,"cmd":"add","timestamp":1491319907087},{"sumCount":33,"revs":6,"author":"a.La7mDukNWjbLvEOg","textCount":8,"cmd":"add","timestamp":1491319908265},{"sumCount":40,"revs":7,"author":"a.La7mDukNWjbLvEOg","textCount":8,"cmd":"add","timestamp":1491319909327},{"sumCount":46,"revs":8,"author":"a.La7mDukNWjbLvEOg","textCount":7,"cmd":"add","timestamp":1491319910459},{"sumCount":47,"revs":9,"author":"a.La7mDukNWjbLvEOg","textCount":2,"cmd":"add","timestamp":1491319911204},{"sumCount":54,"revs":10,"author":"a.La7mDukNWjbLvEOg","textCount":8,"cmd":"add","timestamp":1491319911869},{"sumCount":1,"revs":11,"author":"a.La7mDukNWjbLvEOg","textCount":1,"cmd":"remove","timestamp":1491319915110},{"sumCount":2,"revs":12,"author":"a.La7mDukNWjbLvEOg","textCount":2,"cmd":"add","timestamp":1491319918902},{"sumCount":3,"revs":13,"author":"","textCount":2,"cmd":"add","timestamp":1491319918902},{"sumCount":4,"revs":14,"author":"a.La7mDukNWjbLvEOg","textCount":2,"cmd":"add","timestamp":1491319921225},{"sumCount":5,"revs":15,"author":"a.La7mDukNWjbLvEOg","textCount":2,"cmd":"add","timestamp":1491319923285},{"sumCount":7,"revs":16,"author":"a.La7mDukNWjbLvEOg","textCount":3,"cmd":"add","timestamp":1491319926047},{"sumCount":9,"revs":17,"author":"a.La7mDukNWjbLvEOg","textCount":3,"cmd":"add","timestamp":1491319927179},{"sumCount":17,"revs":18,"author":"a.La7mDukNWjbLvEOg","textCount":9,"cmd":"add","timestamp":1491319929454},{"sumCount":24,"revs":19,"author":"a.La7mDukNWjbLvEOg","textCount":8,"cmd":"add","timestamp":1491319932894},{"sumCount":40,"revs":20,"author":"a.La7mDukNWjbLvEOg","textCount":17,"cmd":"add","timestamp":1491319933397},{"sumCount":56,"revs":21,"author":"a.La7mDukNWjbLvEOg","textCount":17,"cmd":"add","timestamp":1491319933899},{"sumCount":80,"revs":22,"author":"a.La7mDukNWjbLvEOg","textCount":25,"cmd":"add","timestamp":1491319934398},{"sumCount":96,"revs":23,"author":"a.La7mDukNWjbLvEOg","textCount":17,"cmd":"add","timestamp":1491319934898},{"sumCount":104,"revs":24,"author":"a.La7mDukNWjbLvEOg","textCount":9,"cmd":"add","timestamp":1491319935400},{"sumCount":105,"revs":25,"author":"a.o4zSHZzhm3aYPG5Z","textCount":2,"cmd":"add","timestamp":1491319966995},{"sumCount":106,"revs":26,"author":"","textCount":2,"cmd":"add","timestamp":1491319966995},{"sumCount":107,"revs":27,"author":"a.o4zSHZzhm3aYPG5Z","textCount":2,"cmd":"add","timestamp":1491319968063},{"sumCount":108,"revs":28,"author":"a.o4zSHZzhm3aYPG5Z","textCount":2,"cmd":"add","timestamp":1491319970760},{"sumCount":110,"revs":29,"author":"a.o4zSHZzhm3aYPG5Z","textCount":3,"cmd":"add","timestamp":1491319972429},{"sumCount":112,"revs":30,"author":"a.o4zSHZzhm3aYPG5Z","textCount":3,"cmd":"add","timestamp":1491319972987},{"sumCount":119,"revs":31,"author":"a.o4zSHZzhm3aYPG5Z","textCount":8,"cmd":"add","timestamp":1491319976969},{"sumCount":133,"revs":32,"author":"a.o4zSHZzhm3aYPG5Z","textCount":15,"cmd":"add","timestamp":1491319977473},{"sumCount":490,"revs":33,"author":"a.o4zSHZzhm3aYPG5Z","textCount":358,"cmd":"add","timestamp":1491319979398},{"sumCount":497,"revs":34,"author":"a.o4zSHZzhm3aYPG5Z","textCount":8,"cmd":"add","timestamp":1491319979900},{"sumCount":511,"revs":35,"author":"a.o4zSHZzhm3aYPG5Z","textCount":15,"cmd":"add","timestamp":1491319980400},{"sumCount":518,"revs":36,"author":"a.o4zSHZzhm3aYPG5Z","textCount":8,"cmd":"add","timestamp":1491319980911},{"sumCount":519,"revs":37,"author":"a.UsKvmNuj2uefvD8t","textCount":2,"cmd":"add","timestamp":1491320033115},{"sumCount":520,"revs":38,"author":"","textCount":2,"cmd":"add","timestamp":1491320033117},{"sumCount":521,"revs":39,"author":"a.UsKvmNuj2uefvD8t","textCount":2,"cmd":"add","timestamp":1491320034063},{"sumCount":522,"revs":40,"author":"a.UsKvmNuj2uefvD8t","textCount":2,"cmd":"add","timestamp":1491320035060},{"sumCount":524,"revs":41,"author":"a.UsKvmNuj2uefvD8t","textCount":3,"cmd":"add","timestamp":1491320036498},{"sumCount":526,"revs":42,"author":"a.UsKvmNuj2uefvD8t","textCount":3,"cmd":"add","timestamp":1491320037496},{"sumCount":534,"revs":43,"author":"a.UsKvmNuj2uefvD8t","textCount":9,"cmd":"add","timestamp":1491320040681},{"sumCount":527,"revs":44,"author":"a.UsKvmNuj2uefvD8t","textCount":1,"cmd":"remove","timestamp":1491320042919},{"sumCount":535,"revs":45,"author":"a.UsKvmNuj2uefvD8t","textCount":9,"cmd":"add","timestamp":1491320045096},{"sumCount":543,"revs":46,"author":"a.UsKvmNuj2uefvD8t","textCount":9,"cmd":"add","timestamp":1491320045598},{"sumCount":551,"revs":47,"author":"a.UsKvmNuj2uefvD8t","textCount":9,"cmd":"add","timestamp":1491320046740},{"sumCount":567,"revs":48,"author":"a.UsKvmNuj2uefvD8t","textCount":17,"cmd":"add","timestamp":1491320047248},{"sumCount":583,"revs":49,"author":"a.UsKvmNuj2uefvD8t","textCount":17,"cmd":"add","timestamp":1491320047753},{"sumCount":607,"revs":50,"author":"a.UsKvmNuj2uefvD8t","textCount":25,"cmd":"add","timestamp":1491320048254},{"sumCount":615,"revs":51,"author":"a.UsKvmNuj2uefvD8t","textCount":9,"cmd":"add","timestamp":1491320048755},{"sumCount":617,"revs":52,"author":"a.wCrfPGxBu1xbCkFe","textCount":3,"cmd":"add","timestamp":1491320080820},{"sumCount":599,"revs":53,"author":"a.wCrfPGxBu1xbCkFe","textCount":1,"cmd":"remove","timestamp":1491320082810},{"sumCount":601,"revs":54,"author":"a.wCrfPGxBu1xbCkFe","textCount":3,"cmd":"add","timestamp":1491320088203},{"sumCount":603,"revs":55,"author":"a.wCrfPGxBu1xbCkFe","textCount":3,"cmd":"add","timestamp":1491320089661},{"sumCount":605,"revs":56,"author":"a.wCrfPGxBu1xbCkFe","textCount":3,"cmd":"add","timestamp":1491320090928},{"sumCount":611,"revs":57,"author":"a.wCrfPGxBu1xbCkFe","textCount":7,"cmd":"add","timestamp":1491320095258},{"sumCount":629,"revs":58,"author":"a.wCrfPGxBu1xbCkFe","textCount":19,"cmd":"add","timestamp":1491320095762},{"sumCount":647,"revs":59,"author":"a.wCrfPGxBu1xbCkFe","textCount":19,"cmd":"add","timestamp":1491320096262},{"sumCount":653,"revs":60,"author":"a.wCrfPGxBu1xbCkFe","textCount":7,"cmd":"add","timestamp":1491320096762},{"sumCount":947,"revs":61,"author":"a.wCrfPGxBu1xbCkFe","textCount":295,"cmd":"add","timestamp":1491320098417},{"sumCount":953,"revs":62,"author":"a.wCrfPGxBu1xbCkFe","textCount":7,"cmd":"add","timestamp":1491320099003},{"sumCount":971,"revs":63,"author":"a.wCrfPGxBu1xbCkFe","textCount":19,"cmd":"add","timestamp":1491320099507},{"sumCount":989,"revs":64,"author":"a.wCrfPGxBu1xbCkFe","textCount":19,"cmd":"add","timestamp":1491320100008},{"sumCount":1007,"revs":65,"author":"a.wCrfPGxBu1xbCkFe","textCount":19,"cmd":"add","timestamp":1491320100521},{"sumCount":1008,"revs":66,"author":"a.aVZ1yTl62rhX6u9A","textCount":2,"cmd":"add","timestamp":1491320138417},{"sumCount":1010,"revs":67,"author":"a.aVZ1yTl62rhX6u9A","textCount":3,"cmd":"add","timestamp":1491320139427},{"sumCount":1012,"revs":68,"author":"a.aVZ1yTl62rhX6u9A","textCount":3,"cmd":"add","timestamp":1491320140115},{"sumCount":1017,"revs":69,"author":"a.aVZ1yTl62rhX6u9A","textCount":6,"cmd":"add","timestamp":1491320142677},{"sumCount":1027,"revs":70,"author":"a.aVZ1yTl62rhX6u9A","textCount":11,"cmd":"add","timestamp":1491320143177},{"sumCount":1347,"revs":71,"author":"a.aVZ1yTl62rhX6u9A","textCount":321,"cmd":"add","timestamp":1491320145659}];
	//var _user =[{"name":"蔡林","id":"a.wCrfPGxBu1xbCkFe"},{"name":"王雪梅","id":"a.UsKvmNuj2uefvD8t"},{"name":"任梦圆","id":"a.o4zSHZzhm3aYPG5Z"},{"name":"王心蕊","id":"a.La7mDukNWjbLvEOg"},{"name":"林悦婧","id":"a.aVZ1yTl62rhX6u9A"}];
	var _version;
	var _user;
	if(g_type==1){
		
	var groupName='个人'+number;
	}
	else {
		
	var groupName='小组'+number;
	}
	//获取数据
	var start=function(){
		$.ajax({	
    		url:'/pad/getVersion',
    		method:'POST',
    		data:{"groupName":groupName,"assignmentId":assId},
			
    		success:function(data){
    			if(data==null){
    				window.onload();
    			}else{
    			_version=data.version;
    			_user=data.user;
    			 action( "chart1b", "legend1b");
    			}
    		}
    	});
	}
    			
	
	var _focus = [
	                {p: 100, t: 0.5},
	                {p: 95, t: 3},
	                {p: 90, t: 6},
	                {p: 85, t: 10},
	                {p: 80, t: 15},
	                {p: 75, t: 21},
	                {p: 70, t: 38},
	                {p: 65, t: 35},
	                {p: 60, t: 42},
	                {p: 55, t: 50},
	                {p: 50, t: 58},
	                {p: 45, t: 66},
	                {p: 40, t: 75},
	                {p: 35, t: 85},
	                {p: 30, t: 96},
	                {p: 25, t: 108},
	                {p: 20, t: 121},
	                {p: 15, t: 135},
	                {p: 10, t: 150},
	                {p: 5, t: 165},
	                {p: 3, t: 180},
	                {p: 0, t: 200}
	            ];
	window.onload=function(){
		  if (location.href.indexOf("?xyz=")<0)
		 {
		 location.href=location.href+"?xyz="+Math.random();
		 }
		}
	//开始画图
	  start();
	  var addColor = "#00ff00", removeColor = "#ff0000", replaceColor = "#0000ff",seeColor='#00FFFF',commentColor='#68228B',gradeColor='#548B54',replyColor='#7D9EC0';
	 
	 function getActionByVersions(users, versions) {
  	  
        if (!versions || !versions.length ){
       
        
        	return [];
        }else if( versions.length==1){
        	alert("该小组还未进行编辑");
        }
        var temp, x = [], sv = versions[0], add , remove, replace,see,comment,grade,reply, y = [
            [0, ""]
        ], a = 0;
        $.each(users, function (i, n) {
            if (versions && versions.length != 0) {
                temp = getVersionsByAuthorId(versions, n.id);
                add = getAddByVersions(temp);
                remove = getRemoveByVersions(temp);
                replace = getReplaceVersions(temp);
                see=getSeeVersions(temp);
                comment=getCommentVersions(temp);
                grade=getGradeVersions(temp);
                reply=getReplyVersions(temp);
                add =  fn3(n, add, i + 1, addColor, "添加");
                remove =  fn3(n, remove, i + 1, removeColor, "删除");
                replace =  fn3(n, replace, i + 1, replaceColor, "替换");
                see =  fn3(n, see, i + 1, seeColor, "查看图表");
                comment =  fn3(n, comment, i + 1, commentColor, "评论");
                grade =  fn3(n, grade, i + 1, gradeColor, "打分");
                reply =  fn3(n, reply, i + 1, replyColor, "回复");
                x = x.concat(add);
                x = x.concat(remove);
                x = x.concat(replace);
                x = x.concat(see);
                x = x.concat(comment);
                x = x.concat(grade);
                x = x.concat(reply);
                y.push([i + 1, n.name]);
                a = i + 1;
            }
        });
        y.push([a + 1, ""]);
       
        return {x: x, y: y};
    }



      function getAddByVersions(versions) {
          var t = [];
          $.each(versions, function (i, n) {
              if (n.cmd == "add") {
                  t.push(n);
              }
          });
          return t;
      }
      function getRemoveByVersions(versions) {
          var t = [];
          $.each(versions, function (i, n) {
              if (n.cmd == "remove") {
                  t.push(n);
              }
          });
          return t;
      }
       function getReplaceVersions(versions) {
          var t = [];
          $.each(versions, function (i, n) {
              if (n.cmd == "replace") {
                  t.push(n);
              }
          });
          return t;
      }
       function getSeeVersions(versions) {
           var t = [];
           $.each(versions, function (i, n) {
               if (n.cmd == "see") {
                   t.push(n);
               }
           });
           return t;
       }
       function getCommentVersions(versions) {
           var t = [];
           $.each(versions, function (i, n) {
               if (n.cmd == "comment") {
                   t.push(n);
               }
           });
           return t;
       }
       function getGradeVersions(versions) {
           var t = [];
           $.each(versions, function (i, n) {
               if (n.cmd == "grade") {
                   t.push(n);
               }
           });
           return t;
       }
       function getReplyVersions(versions) {
           var t = [];
           $.each(versions, function (i, n) {
               if (n.cmd == "reply") {
                   t.push(n);
               }
           });
           return t;
       }
      
    function getVersionsByAuthorId(versions, authorId) {
          var i, result = [], n;
          n = versions.length;
          for (i = 0; i < n; i++) {
              if (versions[i].author === authorId) {
                  result.push(versions[i]);
              }
          }
          return result;
      }
      

      function fn3(a, v, index, color, cmd, shape) {
          var r = [], t = _focus[0].t * 1000, c = 1;
          for (var i = 1; i < v.length - 1; i++) {
              r.push([v[i].timestamp, index, c, {name: a.name, cmd: cmd, label: a.name + "的" + cmd, color: color, shape: shape}]);
          }

          return r;
      }
      function action(selector, tooltip) {
    	    var data = getActionByVersions(_user, _version);
    	    console.log(data);
    	   dote(data, groupName+"组员行为图", selector, tooltip);
    	}
    	
   
      //画图
      function dote(data, title, selector, tooltip) {
          var plot2 = $.jqplot(selector, [ data.x ], {
              title: title,
              seriesDefaults: {
                  renderer: $.jqplot.BubbleRenderer,
                  rendererOptions: {
                      bubbleAlpha: 0.4,
                      highlightAlpha: 0.8,
                      showLabels: false,
                      //气泡大小
                      autoscaleMultiplier :0.5,
                      autoscalePointsFactor: -0.2
                  },
                  shadow: true,
                  shadowAlpha: 0.05
              },
              cursor: {
                  show: true,
                  zoom: true,
                  showTooltip: false
              },
              axes: {
                  yaxis: {
                      show: true,
                      ticks: data.y,
                      label: "组员"
                  },
                  xaxis: {
                      show: true,
                      label: "时间",
                      renderer: $.jqplot.DateAxisRenderer,
                      tickOptions: {
                    	  formatString : data.x.length > 5 ? "%#m月%d日"
									: "%H:%M"
                      }
                  }
              }
          });
          var v = $("#" + selector);
          v.bind('jqplotDataHighlight', function (ev, seriesIndex, pointIndex, data, radius) {
              var chart_left = v.offset().left, chart_top = v
                      .offset().top, x = plot2.axes.xaxis
                      .u2p(data[0]), // convert x axis unita to
              // pixels
                  y = plot2.axes.yaxis.u2p(data[1]); // convert y
              // axis units to
              // pixels
              var color = 'rgb(50%,50%,100%)', t = $("#"
                  + tooltip);
              var label = $.isPlainObject(data[3]) ? data[3].label
                  : data[3];
              var date = new Date(data[0]);
              t.css({
                  left: chart_left + x + radius - 35,
                  top: chart_top + y + 10,
                  position: "absolute",
                  background: "gainsboro"
              });
              t.html((date.getMonth() + 1) + "月" + date.getDate()
                  + "日" + date.getHours() + ":"
                  + date.getMinutes() + ":"
                  + date.getSeconds() + ":" + data[3].cmd);
              //
              t.show();
          });
          v.bind('jqplotDataUnhighlight', function (ev, seriesIndex, pointIndex, data) {
              var t = $('#' + tooltip);
              t.empty();
              t.hide();
          });
      };
	});
	


</script>
</body>
</html>